home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15670 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: ccshst05.uoguelph.ca!ccshst01!thay
  2. From: thay@uoguelph.ca (Toby K Hay)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: beginner needs help about langtons's ant
  5. Date: 21 Apr 1996 00:53:09 GMT
  6. Organization: University of Guelph
  7. Message-ID: <4lc0tl$ibl@ccshst05.uoguelph.ca>
  8. References: <4lbrsi$4o@usc.edu>
  9. NNTP-Posting-Host: ccshst01.uoguelph.ca
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Zahir Yilmaz Alpaslan (alpaslan) wrote:
  13. : I am trying to implement langton's ant in c.
  14. snip
  15. : When I tried to run this program in unix environment it gave a segmentation
  16. : fault, where did I go wrong?
  17.  
  18. :  char a[100][100];
  19. snip
  20. : int i,j;
  21. : for(i=0;i<=100;i++);
  22. : for(j=0;j<=100;j++);
  23. snip
  24.  
  25. You get a segmentation fault by trying to access memory not allocated to 
  26. your program.  An obvious error of this type is that you declare array 
  27. a[100][100] which will have index values from 0 to 99, but use i and j 
  28. with values from 0 to 100 to access it.  Try: for (i=0;i<100;i++) etc 
  29. instead.  As I look at your code above I see that the for statements each 
  30. have a semicolon after them - an error which will prevent them iterating 
  31. the block of code that follows them as you intended.  You may need to do 
  32. a little debugging yet.
  33. Toby Hay    thay@uoguelph.ca
  34.